<template>
  <div class="x-unit" @click.self="closeMask" :style="{height:`${deviceH}px`}">
    <div class="unit-ctx" :style="{'background-image':`url(${modelBg})`}">
      <div class="ctx-title" v-if="!detailshow">人车关注</div>
      <div class="ctx-info" v-if="!detailshow">
        <div class="info-table">
          <div class="table-rs">
            <div class="table-header">
              <div class="table-finish">
                <div class="table-finish-items">
                      <div
                  style="cursor: pointer;"
                    class="table-finish-item1"
                    :class="{'table-finish-item-active':status==1}"
                    @click="changeStatus(1)"
                  >人员关注</div>
                  <div
                  style="cursor: pointer;"
                    class="table-finish-item3"
                    :class="{'table-finish-item-active':status==2}"
                    @click="changeStatus(2)"
                  >车辆关注</div>
                </div>

                <div class="header-select" >
                    <x-select @selectItem="selectItemCar" :name="unitCarName || '关注类型'" :listItem="unitTypeList" />
                  </div>
              </div>
              <div @click="btnsearch()" class="btnsearch">搜索</div>

            </div>
            <ul class="table-list" v-show="status==1">
               <li class="list-item">
                <div class="item-no">序号</div>
                <div class="item-mjname">姓名</div>
                <div class="item-mjidnum">身份证号</div>
                <div class="item-mjphone">住址</div>
                <div class="item-mjaddress1">关注时间</div>
                <div class="item-mjstatustype">当前状态</div>
                <div class="item-mjidnum">出现时间</div>
                <div class="item-mjphone">信息推送</div>
              </li>
              <li v-for="(item,i) in Personforpage" :key="item.id" style="cursor: pointer;" class="list-item" @click="changeDetail(i)">
                <div class="item-no">{{i+1+pageSize*(pageNum-1)}}</div>
                <div class="item-mjname">{{item.monitorName}}</div>
                <div class="item-mjidnum"  >{{new String().hideidCard(item.idNum)}}</div>
                <div class="item-mjphone">{{item.address}}</div>
                <div class="item-mjaddress1">{{new Date().dateFtt(item.monitorTime,'MM-dd hh:mm:ss')}}</div>
                <div class="item-mjstatustype">{{item.monitorStatus}}</div>
                <div class="item-mjidnum">{{new Date().dateFtt(item.appearanceTime,'MM-dd hh:mm:ss')}}</div>
                <div class="item-mjphone">{{item.informationushP}}</div>

              </li>
            </ul>
            <ul class="table-list" v-show="status==2">
              <li class="list-item">
                <div class="item-no">序号</div>
                <div class="item-mjname">姓名</div>
                <div class="item-mjidnum">身份证号</div>
                <div class="item-mjphone">车牌号</div>
                <div class="item-mjaddress1">关注时间</div>
                <div class="item-mjstatustype">当前状态</div>
                <div class="item-mjidnum">出现时间</div>
                <div class="item-mjphone">信息推送</div>
              </li>
              <li v-for="(item,i) in Carforpage" :key="item.id" class="list-item" @click="changeDetail(i)" style="cursor: pointer;">
                <div class="item-no">{{i+1+pageSize*(pageNum-1)}}</div>
                <div class="item-mjname">{{item.monitorName}}</div>
                <div class="item-mjidnum"  >{{new String().hideidCard(item.idNum)}}</div>
                <div class="item-mjphone">{{item.carNum}}</div>
                <div class="item-mjaddress1">{{new Date().dateFtt(item.monitorTime,'MM-dd hh:mm:ss')}}</div>
                <div class="item-mjstatustype">{{item.monitorStatus}}</div>
                <div class="item-mjidnum">{{new Date().dateFtt(item.appearanceTime,'MM-dd hh:mm:ss')}}</div>
                <div class="item-mjphone">{{item.informationushP}}</div>

              </li>
            </ul>

          </div>
          <div v-if="allpage > 0" class="table-footer">
            <x-page
            :currentPage="pageNum"
              @currentChange="currentChange"
              :page-size="5"
              :allpage="allpage"
              :total-num="false"
            />
          </div>
        </div>
      </div>

      <!-- 详情 -->
      <div v-if="detailshow">
         <div class="ctx-title">关注详情</div>
              <span @click="detailshow= false" style="float:right" class="back">
                <img src="../../assets/images/icon/return.png" alt />
              </span>

        <div style="border:1px solid #246970;width:800px;margin: 0  auto;margin-top:40px" v-if="detailshow">
          <div class="span_title">
            被关注人信息
          </div>
          <div style="display:flex">
              <div class="span_left">姓名</div>
              <div class="span_right" >{{detail.monitorName}}</div>
              <div class="span_left">身份证号</div>
              <div class="span_right">{{new String().hideidCard(detail.idNum)}}</div>
          </div>
          <div style="display:flex">
              <div class="span_left">性别</div>
              <div class="span_right" >{{detail.sex}}</div>
              <div class="span_left">出生日期</div>
              <div class="span_right">{{detail.birthday}}</div>
          </div>
          <div style="display:flex">
              <div class="span_left">单元</div>
              <div class="span_right" >{{detail.unitNo}}</div>
              <div class="span_left">门牌号</div>
              <div class="span_right">{{detail.houseNo}}</div>
          </div>
            <div class="span_title">
            关注人信息
          </div>
          <div style="display:flex">
              <div class="span_left">姓名</div>
              <div class="span_right" >{{detail.name}}</div>
              <div class="span_left">类型</div>
              <div class="span_right">{{detail.type}}</div>
          </div>
          <div style="display:flex">
              <div class="span_left">联系电话</div>
              <div class="span_right" >{{detail.phone}}</div>
              <div class="span_left">通知方式</div>
              <div class="span_right">{{detail.methodToInforme}}</div>
          </div>


        </div>
      </div>


      </div>




  </div>
</template>
<script>
import {
  monitorPersonPageList,
  monitorCarPageList,
} from "@/api/peopleApi";
import XPage from "@/components/xpage";
import XSelect from "@/components/xselect";
import user from '@/api/user.json'
import XDangan from '@/components/xdanganmodel'
export default {
  name: "xunitmodel",
  props: {
    id: {
      type: String,
      default: ""
    },
    code: {
      type: String,
      default: ""
    }
  },
  computed: {},
  data() {
    return {
      modelBg: require("@/assets/images/modelBg.png"),
      deviceH: 0,
      lengalperson: "", //法人
      lpTelePhone: "", //法人电话
      lpidCard: "", //法人身份证号
      unitName: "", //单位名称,
      unitTelePhone: "", //单位电话
      unitType: 0, //单位类型
      unitTypeName: "", //单位名称
      pageSize: 12,
      pageNum: 1,
      Personforpage: [],
      Carforpage: [],
      UnitTypeEchartsData1: null,
      UnitTypeEchartsData2: [],
      total: 0,
      allpage: 0,
      detailshow: false,
      unitTypeList: [
        { enumName: "全部", id: "" },
        { enumName: "关注中", id: "0" },
        { enumName: "解除关注", id: "1" }
      ],
      unitCar:'',
      unitCarName:'',
      status:1, //1 人 2 车
      detail:{},
      camerquery: {},
      finishactive: 0,
      housedeclarforpage: [],
      gatedpersonforpage: [],
      doorAccessforpage:[]
    };
  },
  components: {
    XPage,
    XSelect,
    XDangan
  },
  beforeMount() {
    let h = document.documentElement.clientHeight || document.body.clientHeight;
    this.deviceH = h;
  },
     filters:{
       filterName(val) {
         var name=''
         user.map(item=>{
           if(item.userid==val){
             name=item.truename
           }

         })
        return name
      }
    },
  mounted() {
     this.GetPersonPageList();
  },
  methods: {
    changeDetail(index){
      this.detailshow=true;
      if(this.status==1){
        this.detail=this.Personforpage[index]
      }else{
        this.detail=this.Carforpage[index]
      }
    },
    btnsearch(){
      if(this.status==1){
        this.GetPersonPageList()
      }else{
         this.GetCarPageList()
      }
    },
    selectItemCar(name,id){

      this.unitCarName = name
      this.unitCar = id
    },
    changeStatus(status){
      this.status=status
      this.pageNum = 1
      if(status==1){
        this.GetPersonPageList()
      }
      if(status==2){
        this.GetCarPageList()
      }



    },
    async GetPersonPageList(){
      let params={
        placeId:this.code,
        pageSize:this.pageSize,
        pageNum:this.pageNum,
        monitorStatus:"0"
      }
      let res = await monitorPersonPageList(params);
      this.total = res.total;
      console.log(res)
      this.allpage = Math.ceil(this.total / this.pageSize);
      this.Personforpage = res.list;
    },
     async GetCarPageList(){
      let params={
        placeId:this.code,
        pageSize:this.pageSize,
        pageNum:this.pageNum,
        monitorStatus:"0"
      }
      let res = await monitorCarPageList(params);
      this.total = res.total;
      console.log(res)
      this.allpage = Math.ceil(this.total / this.pageSize);
      this.Carforpage = res.list;
    },
    async GetHouseDeclarForPage() {
      var _this = this;
      let params = {};
      _this.housedeclarforpage = [];
      params.placeId = _this.code;
      params.statusType = _this.finishactive;
      params.pageSize = _this.pageSize;
      params.pageNum = _this.pageNum;
      console.log(params);
      let housedeclarforpage = await GetHouseDeclarForPage(params);
      console.log(housedeclarforpage);
      _this.total = housedeclarforpage.total;
      console.log(_this.total);
      this.allpage = Math.ceil(this.total / this.pageSize);
      console.log(this.allpage);
      _this.housedeclarforpage = housedeclarforpage.list;
      console.log(JSON.stringify(_this.housedeclarforpage));
    },
    async GetGatedPersonForPage() {
      var _this = this;
      let params = {};
      _this.gatedpersonforpage = [];
      params.placeId = _this.code;
      params.statusType = _this.finishactive;
      params.pageSize = _this.pageSize;
      params.pageNum = _this.pageNum;
      console.log(params);
      let gatedpersonforpage = await GetGatedPersonForPage(params);
      console.log(gatedpersonforpage);
      _this.total = gatedpersonforpage.total;
      console.log(_this.total);
      this.allpage = Math.ceil(this.total / this.pageSize);
      console.log(this.allpage);
      _this.gatedpersonforpage = gatedpersonforpage.list;
      console.log(JSON.stringify(_this.gatedpersonforpage));
    },

    async GetUnitData() {
      try {
        let camerquery = {
          code: this.code,
          id: this.id
        };
        this.camerquery = camerquery;
        let pagequery = {
          code: this.code,
          id: this.id,
          lengalperson: this.lengalperson, //法人
          lpTelePhone: this.lpTelePhone, //法人电话
          lpidCard: this.lpidCard, //法人身份证号
          unitName: this.unitName, //单位名称,
          unitTelePhone: this.unitTelePhone, //单位电话
          unitType: this.unitType, //单位类型
          pageNum: this.pageNum,
          pageSize: this.pageSize
        };
        console.log(pagequery);
        this.UnitTypeEchartsData = await GetUnitTotleAndType(camerquery);

        console.log("_+_+_+");
        console.log(this.UnitTypeEchartsData);
        this.UnitTypeEchartsData1 = this.UnitTypeEchartsData[0];
        this.UnitTypeEchartsData2 = this.UnitTypeEchartsData.splice(
          1,
          this.UnitTypeEchartsData.length
        );

        const res = await GetUnitInfoForPage(pagequery);
        console.log("_+_+_+");
        console.log(res);
        this.total = res.data.total;
        this.allpage = Math.ceil(this.total / this.pageSize);
        console.log(this.allpage);
        this.UnitPageEchartsData = res.data.list;
      } catch (error) {
        this.$message({
          type: "error",
          message: error
        });
      }
    },

    closeMask() {
      this.$emit("closeMask");
    },
    //分页
    currentChange(n) {
      console.log("分页");
      this.pageNum = n;
      if (this.status==0) {
        this.GetHouseDeclarForPage();
      }
      if(this.status==1){
        this.GetGatedPersonForPage();
      }
      if(this.status==2){
        this.GetDoorAccessForThreeDay()
      }
    },
    //搜索
    searchEvent() {
      var _this = this;
      if (_this.unitType == 0 || _this.unitType == "") {
        _this.pageNum = 1;
        _this.GetHouseDeclarForPage();
      } else {
        _this.pageNum = 1;
        _this.GetGatedPersonForPage();
      }
       this.currentChange(1)
    },
    //选择下拉框
    selectItem(name, id) {
      this.unitTypeName = name;
      this.unitType = id;
    },

    //已完成待完成
    ifFinishActive(num) {
      var _this = this;
      if (num == 0) {
        _this.finishactive = 0;
      } else if (num == 1) {
        _this.finishactive = 1;
      }
    }
  }
};
</script>
<style lang="less" scoped>
 .back {
      float: right;
      position: absolute;
      right: 60px;
      width: 0px;
      top: 30px;
      cursor: pointer;

      img {
        width: 30px;
        height: 30px;
      }
    }
     .span_left {
    background: rgba(27, 58, 61, 0.75);
    border: 1px solid #246970;
    padding-right: 15px;
    text-align: right;
    color: #ffffff;
    width: 150px;
    height: 50px;
    line-height: 50px;
  }
  .span_title{
     background: rgba(27, 58, 61, 0.75);
    border: 1px solid #246970;
     text-align: center;
    color: #ffffff;
     height: 50px;
    line-height: 50px;
  }
    .span_right {
    padding-left: 20px;
    text-align: left;
    color: #ffffff;
    border: 1px solid #246970;
    width: 250px;
    height: 50px;
    line-height: 50px;
  }
	.btnsearch {
		float: right;
		width: 66px;
		height: 100%;
		background: #72edf5;
		border-radius: 4px;
		text-align: center;
		line-height: 36px;
		font-family: PingFangSC-Regular;
		font-size: 14px;
		color: #000000;
    cursor:pointer;
	}
/*门禁*/
.item-mjname {
  color: #fff;
  width: 107px;
}
.item-mjidnum {
  color: #fff;
  width: 150px;
}
.item-mjphone {
  color: #fff;
  width: 170px;
}
.item-mjaddress {
  color: #fff;
  width: 170px;
}
.item-mjaddress1 {
  color: #fff;
  width: 200px;
}
.item-mjstatustype {
  color: #fff;
  width: 120px;
}

  .item-mjupdateName {
    color: #fff;
    width: 150px;
    overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
  }

  .item-mjupdateTime {
    color: #fff;
    width: 150px;
  }

/*房屋*/
.item-fwaddress {
  color: #fff;
  width: 107px;
}

.item-fwname {
  color: #fff;
  width: 150px;
}

.item-fwidNum {
  color: #fff;
  width: 170px;
}

.item-fwphone {
  color: #fff;
  width: 170px;
}

.item-fwstatusType {
  color: #fff;
  width: 150px;
}

  .item-fwupdateName {
    color: #fff;
    width: 150px;
  }

  .item-fwupdateTime {
    color: #fff;
    width: 150px;
  }

.table-finish {
  height: 36px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
}
.table-finish-items {
  height: 36px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
}
.table-finish-item1 {
  // width: 70px;
  height: 36px;
  line-height: 36px;
  background: #06121d;
  color: #fff;
  border-radius: 4px 0 0 4px;
  padding: 0 10px;
  margin-right: 5px;
}

.table-finish-item2 {
  width: 70px;
  height: 36px;
  line-height: 36px;
  background: #06121d;
  color: #fff;
  // border-radius: 0 4px 4px 0;
  padding: 0 10px;
}

.table-finish-item3 {
  // width: 70px;
  height: 36px;
  line-height: 36px;
  background: #06121d;
  color: #fff;
  border-radius: 0 4px 4px 0;
  padding: 0 10px;
}

.table-finish-item-active {
  background: #72edf5;
  color: #000;
}

.x-unit {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  .item-pie {
    width: 100%;
    height: 400px;
    margin-top: 10px;
    padding: 5px 0px;
    box-sizing: border-box;
    .pie-canvas {
      width: 100%;
      height: 100%;
    }
  }
  .unit-ctx {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 1177px;
    height: 800px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
    padding: 10px 30px;
    box-sizing: border-box;
    .ctx-title {
      width: 100%;
      padding-top: 10px;
      box-sizing: border-box;
      font-family: PingFangSC-Medium;
      font-size: 24px;
      color: #e9e9e9;
      letter-spacing: 4.8px;
      text-align: center;
      box-sizing: border-box;
    }
    .ctx-info {
      width: 100%;

      height: 748px;
      padding-top: 20px;
      box-sizing: border-box;
      display: flex;
      justify-content: space-around;
      align-items: flex-start;
      .info-type {
        flex: 1;
        .type-title {
          width: 100%;
          font-family: PingFangSC-Medium;
          font-size: 18px;
          color: #69d3da;
          letter-spacing: 0;
          text-align: left;
          line-height: 36px;
        }
        .type-list {
          width: 100%;
          padding: 0;
          margin-top: 26px;
          list-style: none;
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          box-sizing: border-box;
          .type-list-rs {
            width: 100%;
            list-style: none;
            margin-bottom: 20px;
            .rs-name {
              width: 100%;
              display: flex;
              justify-content: space-around;
              align-items: center;
              font-family: PingFangSC-Regular;
              font-size: 12px;
              color: #e5e5e5;
              margin-bottom: 5px;
              .name {
                flex: 1;
                text-align: left;
              }
              .number {
                flex: 1;
                text-align: right;
              }
            }
            .rs-process {
              width: 100%;
              height: 6px;
              border-radius: 4px;
              background: #333333;
              .process {
                transition: width 0.3s ease-in-out;
                height: 100%;
                border-radius: 4px;
                background-image: linear-gradient(
                  270deg,
                  #68e0cf 0%,
                  #209cff 100%
                );
              }
            }
          }
        }
      }
      .info-table {
        flex: 3;
        height: 659px;
        padding-left: 20px;
        padding-right: 20px;
        box-sizing: border-box;
        .table-rs {
          width: 100%;
          height: 562px;
          overflow-y: auto;
          .table-header {
            width: 100%;
            height: 36px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            .header-item {
              width: 186px;
              height: 100%;
              border: none;
              outline: none;
              background: #06121d;
              border: 1px solid rgba(62, 178, 215, 0);
              border-radius: 4px;
              font-size: 14px;
              color: #fff;
              padding: 0 14px;
              box-sizing: border-box;
              .input {
                font-size: 14px;
                color: #fff;
                width: 100%;
                height: 100%;
                border: none;
                outline: none;
                background: transparent;
              }
            }
            .header-select {
              width: 186px;
              margin-left: 20px;
              height: 100%;
            }
            .header-more {
              width: 56px;
              margin-left: 20px;
              font-family: PingFangSC-Regular;
              font-size: 14px;
              color: #72edf5;
              line-height: 28px;
              text-decoration: underline;
            }
            .header-btn {
              width: 66px;
              height: 100%;
              background: #72edf5;
              border-radius: 4px;
              text-align: center;
              line-height: 36px;
              font-family: PingFangSC-Regular;
              font-size: 14px;
              color: #000000;
            }
          }
          .table-list {
            width: 100%;
            list-style: none;
            padding: 0;
            margin-top: 15px;
            .list-item {
              padding: 0;
              margin: 0;
              list-style: none;
              width: 100%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              height: 36px;
              &:nth-of-type(2n + 1) {
                background: #06121d;
              }
              &:nth-of-type(2n) {
                background: transparent;
              }
              .item-no {
                width: 50px;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-align: center;
              }
              .item-pic {
                width: 120px;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-align: center;
              }
              .item-name {
                width: 158px;
                text-align: left;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
              }
              .item-type {
                width: 116px;
                text-align: left;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
              }
              .item-phone {
                width: 125px;
                text-align: left;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
              }
              .item-people {
                width: 116px;
                text-align: left;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
              }
              .item-cardid {
                width: 194px;
                text-align: left;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
              }
            }
          }
        }
        .table-footer {
          width: 100%;
          padding-top: 60px;
          box-sizing: border-box;
          display: flex;
          justify-content: flex-end;
        }
      }
    }
  }
}
</style>
